import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { Client } from "@/pages/base/client/entity";

interface SingleCustomerSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedCustomer?: Client) => void;
}

const SingleCustomerSelector:React.FC<SingleCustomerSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的供应商
  const [selectedCustomer, setSelectedCustomer] = useState<Client>();

  const handleOk = () => {
		onOk(selectedCustomer);
	};

	return (
		<Modal title="选择客户" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="customer_select_report"
        selectionType={SelectionType.RADIO}
        onSelectChange={(selectedRows) => {setSelectedCustomer(selectedRows[0])}}  
      />
		</Modal>
	);
}

export default SingleCustomerSelector;